﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using VOL;

namespace WebQuyPhong
{
    public partial class QuanLyThuCB : System.Web.UI.Page
    {
        ThuQuyBL _thuQuyBLL = new ThuQuyBL();
        DMCanBo _CanBo = new DMCanBo();
        int idcanbo, namthu;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                loadcomboCB();
                loadcomboNam();
                //set hiển thị năm hiện tại
                dllNam.SelectedValue = DateTime.Now.Year.ToString();
                _CanBo = (DMCanBo)HttpContext.Current.Session["Login"];

                dllCanBo.SelectedValue = _CanBo.IDCanBo.ToString();

                idcanbo = _CanBo.IDCanBo;

                namthu = int.Parse(dllNam.SelectedValue);

                FillData(idcanbo, namthu);
            }
        }
        private void FillData(int idcanbo, int nam)
        {
            GridView1.DataSource = _thuQuyBLL.GetDataCB(idcanbo, nam);
            GridView1.DataBind();
        }

        private void loadcomboCB()
        {
            //load combo can bo;
            DMCanBoBL _dmCanBoBl = new DMCanBoBL();
            dllCanBo.DataSource = _dmCanBoBl.GetDataCB();
            dllCanBo.DataValueField = "IDCANBO";
            dllCanBo.DataTextField = "HOTEN";
            dllCanBo.DataBind();
            dllCanBo.Items.Insert(0, "- Vui lòng Chọn -");
        }

        private void loadcomboNam()
        {
            dllNam.Items.Insert(0, "- Vui lòng Chọn -");
            //load combo nam
            int i = 2009, j = 1;
            while (i <= DateTime.Now.Year)
            {
                dllNam.Items.Insert(j, i.ToString());
                j = j + 1;
                i = i + 1;
            }
        }

        protected void btnXem_Click(object sender, EventArgs e)
        {
            idcanbo = int.Parse(dllCanBo.SelectedValue);
            namthu = int.Parse(dllNam.SelectedValue);

            FillData(idcanbo, namthu);
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            GridView1.DataBind();
        }
    }
}